#!/bin/bash

# 这三个变量修改为自己实际的位置即可
INI="/etc/uwsgi9090.ini"
UWSGI="/root/.virtualenvs/env_xadmin/bin/uwsgi"
PIDFILE="/var/run/uwsgi9090.pid"

PSID="ps aux | grep "uwsgi"| grep -v "grep" | wc -l"


if [ ! -n "$1" ]
then
    content="Usages: sh uwsgiserver.sh [start|stop|restart]"
    echo -e "\033[31m $content \033[0m"
    exit 0
fi
 
if [ $1 = start ]
then
    if [ `eval $PSID` -gt 1 ]
    then
        content="uwsgi is running!"
        echo -e "\033[32m $content \033[0m"
        exit 0
    else
        $UWSGI $INI
        content="Start uwsgi service [OK]"
        echo -e "\033[32m $content \033[0m"
    fi
 elif [ $1 = stop ];then
    if [ `eval $PSID` -gt 1 ];then
        $UWSGI --stop $PIDFILE
    fi
    content="Stop uwsgi service [OK]"
    echo -e "\033[32m $content \033[0m"
elif [ $1 = restart ];then
    if [ `eval $PSID` -gt 1 ];then
	echo -e  "restart stop"
	$UWSGI --stop $PIDFILE
    fi
    echo -e "start..."
    sleep 1
    $UWSGI --ini $INI
    content="Restart uwsgi service [OK]"
    echo -e "\033[32m $content \033[0m"

else
    content="Usages: sh uwsgiserver.sh [start|stop|restart]"
    echo -e "\033[31m $content \033[0m"
fi
